home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revolution - Das Atari CD Magazin 1997
/
Revolution - Das Atari CD Magazin 1.iso
/
software
/
anwendng
/
qed_397
/
sourcen
/
clipbrd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-29
|
15KB
|
684 lines
#include "global.h"
#include "comm.h"
#include "desktop.h"
#include "edit.h"
#include "file.h"
#include "icon.h"
#include "options.h"
#include "printer.h"
#include "rsc.h"
#include "scroll.h"
#include "set.h"
#include "text.h"
#include "umbruch.h"
#include "windows.h"
#include "clipbrd.h"
/* exportierte Variablen ***************************************************/
WORD iclipbrd, clip_type;
/****** DEFINES ************************************************************/
#define KIND (NAME|CLOSER|FULLER|MOVER|SIZER|UPARROW|DNARROW|VSLIDE|LFARROW|RTARROW|HSLIDE)
#define FLAGS (WI_TEXT|WI_FONTSIZE)
#define MAX_UNDO 5
#define END_UNDO -1
/* loake Variablen *********************************************************/
LOCAL TEXTP clip_text = NULL;
LOCAL BOOLEAN clip_on_disk;
LOCAL FSEL fsel;
LOCAL LONG clip_time = -1;
LOCAL BOOLEAN clip_dirty, clip_empty;
LOCAL WORD undo[MAX_UNDO];
LOCAL WORD undo_anz;
LOCAL RING undo_text;
LOCAL WORD undo_ptr;
/* lokale Prototypen *******************************************************/
LOCAL VOID set_scrapname (VOID);
LOCAL VOID icon_exist (WORD icon, SET actions);
LOCAL BOOLEAN icon_test (WORD icon, WORD action);
LOCAL WORD icon_edit (WORD icon, WORD action);
LOCAL BOOLEAN icon_drag (WORD icon, WORD source);
LOCAL VOID crt_clipbrd (WORD icon, WINDP window);
LOCAL BOOLEAN open_clipbrd (WINDP window);
LOCAL VOID flush_clipbrd (VOID);
LOCAL VOID load_clipbrd (VOID);
LOCAL BOOLEAN scrap_print (VOID);
/***************************************************************************/
VOID clr_undo(VOID)
{
undo_ptr = -1;
undo_anz = 0;
}
BOOLEAN any_undo(VOID)
{
if (undo_anz && undo[undo_anz-1]==END_UNDO)
return TRUE;
return FALSE;
}
BOOLEAN test_col_anders(VOID)
{
WORD i;
if (undo_anz == 0)
return FALSE;
if (undo[undo_anz-1] == COL_ANDERS)
return TRUE;
if (undo[undo_anz-1] != END_UNDO)
return FALSE;
for (i = 0; i < undo_anz; i++)
if (undo[i]==END_UNDO)
break;
if (i > 0 && i < undo_anz)
return (undo[i-1] == COL_ANDERS);
return FALSE;
}
VOID end_undo_seq(VOID)
{
WORD i;
undo_ptr = -1;
if (undo_anz==0 || undo[undo_anz-1]==END_UNDO)
return;
for (i=0; i<undo_anz; i++)
if (undo[i]==END_UNDO)
{
i++;
undo_anz -= i;
COPYW(undo, undo+i, (short) sizeof(WORD) * undo_anz);
break;
}
add_undo(END_UNDO);
}
VOID add_undo(WORD undo_op)
{
if (undo_anz<MAX_UNDO && (undo_anz==0 || undo[undo_anz-1]!=undo_op))
undo[undo_anz++] = undo_op;
}
WORD get_undo(VOID)
{
WORD i;
if (undo_anz==0)
return NO_UNDO;
if (undo_ptr<0)
{
for (i=0; i<undo_anz; i++)
if (undo[i]==END_UNDO) break;
if (i==undo_anz) return NO_UNDO;
undo_ptr = i;
}
undo_ptr--;
if (undo_ptr<0)
return NO_UNDO;
return undo[undo_ptr];
}
BOOLEAN clip_ondisk(BOOLEAN flag)
{
if (flag)
clip_on_disk = TRUE;
else
clip_on_disk = FALSE;
if (clip_text != NULL) /* wird vor init. aufgerufen */
{
if (scrapdir[0]==EOS)
clip_on_disk = FALSE;
set_scrapname();
load_clipbrd();
}
return clip_on_disk;
}
BOOLEAN is_clip_ondisk(VOID)
{
return clip_on_disk;
}
LOCAL VOID set_scrapname(VOID)
{
if (clip_on_disk)
{
PATH str;
strcpy(str, scrapdir);
strcat(str, "SCRAP.TXT");
set_text_name(clip_text, str, FALSE);
}
else
{
CICONBLK *cicon;
cicon = (CICONBLK *)get_obspec(icons, ICLIP);
set_text_name(clip_text, cicon->monoblk.ib_ptext, TRUE);
}
}
LOCAL VOID flush_clipbrd(VOID)
{
BOOLEAN b;
if (clip_on_disk && clip_dirty)
{
set_scrapname();
b = clip_text->loc_opt->backup;
clip_text->loc_opt->backup = FALSE;
clip_text->file_date_time = -1L; /* damit keine Meldung kommt */
clip_text->ending = tos;
scrap_clear(); /* SCRAP.* löschen */
save(clip_text);
send_clip_change();
clip_text->loc_opt->backup = b;
clip_time = clip_text->file_date_time;
clip_dirty = FALSE;
}
}
LOCAL VOID clear_clip(VOID)
{
clear_text(clip_text);
clip_text->cursor = FALSE;
set_scrapname();
}
LOCAL VOID test_clipbrd(VOID)
{
if (clip_text!=NULL && clip_empty!=ist_leer(&clip_text->text))
{
clip_empty ^= TRUE;
change_icon_on_desk(iclipbrd,clip_empty?ICLIP:ICLIPFULL);
}
}
LOCAL VOID load_clipbrd(VOID)
{
LONG help;
if (!clip_on_disk)
return;
if (file_exist(clip_text->filename))
{
help = file_time(clip_text->filename,NULL,NULL);
if (help!=clip_time) /* wurde von anderem Programm geändert */
{
clip_time = help;
clear_clip();
if (load(clip_text, TRUE)!=0) /* Speichermangel oder Lesefehler */
clear_clip();
make_chg(iclipbrd,TOTAL_CHANGE,0);
restore_edit();
test_clipbrd(); /* Icon richtig? */
}
}
else
{
clip_time = -1;
clear_clip();
make_chg(iclipbrd,TOTAL_CHANGE,0);
restore_edit();
test_clipbrd(); /* Icon richtig? */
}
}
/***************************************************************************/
/* Drucken des Clipbrd */
/***************************************************************************/
LOCAL BOOLEAN scrap_print(VOID)
{
BOOLEAN ok;
ok = TRUE;
load_clipbrd();
if (ist_leer(&clip_text->text))
{
note(1,CLIPEMPT);
ok = FALSE;
}
if (ok)
{
FILENAME name;
set_scrapname();
if (clip_on_disk)
file_name(clip_text->filename, name, FALSE);
else
strcpy(name, clip_text->filename);
if (prn_options(name, FALSE))
txt_drucken(name, clip_text);
}
return(ok);
}
/***************************************************************************/
/* Operation vorhanden */
/***************************************************************************/
LOCAL VOID icon_exist(WORD icon, SET actions)
{
WINDP window;
window = get_window(icon);
setclr(actions);
setincl(actions,DO_INIT);
setincl(actions,DO_CLEAR);
if (window->opened)
setincl(actions,DO_CLOSE);
setincl(actions,DO_OPEN);
setincl(actions,DO_DESTRUCT);
setincl(actions,DO_INFO);
setincl(actions,DO_HELP);
setincl(actions,DO_PRINT);
setincl(actions,DO_SAVENEW);
setincl(actions,DO_REINIT);
setincl(actions,DO_UPDATE);
}
/***************************************************************************/
/* Operation testen */
/***************************************************************************/
LOCAL BOOLEAN icon_test(WORD icon, WORD action)
{
BOOLEAN erg;
WINDP window;
window = get_window(icon);
switch(action)
{
case DO_CLOSE :
erg = window->opened;
break;
case DO_INIT :
case DO_CLEAR :
case DO_OPEN :
case DO_DESTRUCT:
case DO_INFO :
case DO_HELP :
case DO_PRINT :
case DO_SAVENEW:
case DO_UPDATE :
case DO_REINIT :
erg = TRUE;
break;
default :
erg = FALSE;
}
return erg;
}
/***************************************************************************/
/* Operation durchführen */
/***************************************************************************/
LOCAL WORD icon_edit(WORD icon, WORD action)
{
WORD erg = 1;
WINDOWP window;
PATH name;
window = get_window(icon);
switch(action)
{
case DO_INIT :
clip_text = new_text(icon);
create_window(KIND,CLASS_CLIP,icon,crt_clipbrd);
load_clipbrd();
break;
case DO_CLEAR :
clear_clip();
if (clip_on_disk)
scrap_clear();
make_chg(icon,TOTAL_CHANGE,0);
restore_edit();
break;
case DO_CLOSE :
close_window(window);
break;
case DO_DESTRUCT:
destruct_window(window);
destruct_text(clip_text);
clip_text = NULL;
clip_time = -1;
kill_textring(&undo_text);
break;
case DO_OPEN :
if (!open_clipbrd (window))
erg = -1;
break;
case DO_INFO :
load_clipbrd();
info_edit(icon);
break;
case DO_HELP :
note (1, HELPCLIP);
break;
case DO_PRINT :
scrap_print();
break;
case DO_SAVENEW:
load_clipbrd();
if (ist_leer(&clip_text->text))
{
note(1,CLIPEMPT);
erg = -1;
}
else
{
if (save_new(name, &fsel, STRING(SAVECLIPSTR)))
{
erg = save_as(clip_text,name);
if (erg==0) erg = 1;
}
}
break;
case DO_REINIT :
clip_text = new_text(icon);
init_textring(&undo_text);
create_window(KIND,CLASS_CLIP,icon,crt_clipbrd);
load_clipbrd();
break;
case DO_UPDATE :
flush_clipbrd();
load_clipbrd();
break;
}
test_clipbrd(); /* Icon richtig? */
return erg;
}
/***************************************************************************/
/* Reaktion des Verschiebens auf das CLIPBRD-Icon */
/***************************************************************************/
LOCAL BOOLEAN icon_drag (WORD icon, WORD source)
{
RING t;
TEXTP t_ptr = get_text(source);
if (t_ptr!=NULL)
{
init_textring(&t);
if (!doppeln(&t_ptr->text,&t))
{
kill_textring(&t);
return FALSE;
}
if (global_shift)
clip_add_text(&t);
else
clip_takes_text(&t);
restore_edit();
return TRUE;
}
return FALSE;
}
/***************************************************************************/
VOID undo_takes_text(RINGP r)
{
kill_textring(&undo_text);
undo_text = *r;
FIRST(r)->vorg = &undo_text.head;
LAST(r)->nachf = &undo_text.tail;
}
RINGP get_undo_text(VOID)
{
return &undo_text;
}
/***************************************************************************/
VOID clip_takes_text(RINGP r)
{
TEXTP t_ptr = clip_text;
kill_textring(&t_ptr->text);
t_ptr->text = *r;
FIRST(r)->vorg = &t_ptr->text.head;
LAST(r)->nachf = &t_ptr->text.tail;
t_ptr->cursor_line = FIRST(&t_ptr->text);
make_chg(iclipbrd,TOTAL_CHANGE,0);
clip_dirty = TRUE;
test_clipbrd(); /* Icon richtig? */
}
VOID clip_add_text(RINGP r)
{
TEXTP t_ptr = clip_text;
LINEP col;
col = LAST(&t_ptr->text); /* letzte Zeile */
col->nachf = FIRST(r);
FIRST(r)->vorg = col;
LAST(r)->nachf = &t_ptr->text.tail;
LAST(&t_ptr->text) = LAST(r);
t_ptr->text.lines += r->lines;
col_concate(&col);
t_ptr->text.lines--;
make_chg(iclipbrd, TOTAL_CHANGE, 0);
clip_dirty = TRUE;
test_clipbrd(); /* Icon richtig? */
}
/***************************************************************************/
LOCAL BOOLEAN wi_key(WINDOWP window, MKINFO *mk)
{
BOOLEAN erg;
WORD key_code;
erg = FALSE;
if (mk->kreturn & NKF_FUNC)
{
if (mk->kreturn & NKF_SHIFT) /* alle Shift-Codes */
{
key_code = mk->kreturn & ~(NKF_FUNC|NKF_SHIFT);
switch (key_code)
{
case NK_CLRHOME:
v_slider(window,1000);
erg = TRUE;
break;
case NK_UP:
arrow_window(window, WA_UPPAGE, 1);
erg = TRUE;
break;
case NK_DOWN:
arrow_window(window, WA_DNPAGE, 1);
erg = TRUE;
break;
case NK_LEFT:
arrow_window(window, WA_LFPAGE, 1);
erg = TRUE;
break;
case NK_RIGHT:
arrow_window(window, WA_RTPAGE, 1);
erg = TRUE;
break;
default:
erg = FALSE;
}
}
else
{
key_code = mk->kreturn & ~NKF_FUNC;;
switch (key_code)
{
case NK_CLRHOME :
v_slider(window, 0);
erg = TRUE;
break;
case NK_UP:
arrow_window(window, WA_UPLINE, 1);
erg = TRUE;
break;
case NK_DOWN :
arrow_window(window, WA_DNLINE, 1);
erg = TRUE;
break;
case NK_LEFT :
arrow_window(window, WA_LFLINE, 1);
erg = TRUE;
break;
case NK_RIGHT:
arrow_window(window, WA_RTLINE, 1);
erg = TRUE;
break;
case NK_M_PGUP: /* Mac: page up -> shift-up */
arrow_window(window, WA_UPPAGE, 1);
erg = TRUE;
break;
case NK_M_PGDOWN: /* Mac: page down -> shift-down */
arrow_window(window, WA_DNPAGE, 1);
erg = TRUE;
break;
case NK_M_END: /* Mac: end -> shift-home */
v_slider(window,1000);
erg = TRUE;
break;
default:
erg = FALSE;
}
}
}
else
erg = FALSE;
return (erg);
}
/***************************************************************************/
/* Kreieren eines Fensters */
/***************************************************************************/
LOCAL VOID crt_clipbrd (WORD icon, WINDOWP window)
{
WORD initw, inith;
CICONBLK *cicon;
clip_text->cursor = FALSE;
clip_text->ending = tos;
set_scrapname();
initw = min (desk.w / gl_wchar * gl_wchar - 7 * gl_wchar, 80 * gl_wchar);
inith = (desk.h / gl_hchar) * gl_wchar - 7 * gl_hchar;
window->flags = FLAGS;
window->doc.w = MAX_LINE_LEN;
window->doc.h = clip_text->text.lines;
window->xfac = gl_wchar;
window->yfac = gl_hchar;
window->w_width = initw/gl_wchar;
window->w_hight = inith/gl_hchar;
window->work.x = sys_wchar;
window->work.y = 42;
window->work.w = initw;
window->work.h = inith;
window->draw = wi_draw_edit; /* gleiche Routinen wie für EDIT */
window->key = wi_key;
cicon = (CICONBLK *)get_obspec(icons, ICLIP);
set_wname(window, cicon->monoblk.ib_ptext);
} /* crt_clipbrd */
/***************************************************************************/
/* Öffnen des Objekts */
/***************************************************************************/
LOCAL BOOLEAN open_clipbrd (WINDOWP window)
{
BOOLEAN ok;
if (window->opened)
/* Doppelklick auf Icon und Fenster ist schon offen */
{
top_window (window);
ok = TRUE;
}
else
{
load_clipbrd();
ok = open_window(window);
}
return (ok);
} /* open_clipbrd */
/***************************************************************************/
VOID init_clipbrd(VOID)
{
PATH s;
UBYTE *str;
CICONBLK *cicon;
scrp_read (scrapdir); /* Scrap-Directory lesen */
if (scrapdir[0] == EOS) /* Noch keines gesetzt */
{
if ((str=getenv("SCRAPDIR"))!=NULL && *str!=EOS)
strcpy(scrapdir, str);
else if ((str=getenv("CLIPBRD"))!=NULL && *str!=EOS)
strcpy(scrapdir, str);
else
{
WORD drive;
strcpy (scrapdir, "A:\\CLIPBRD\\");
drive = get_first_drive();
if (drive > 0)
scrapdir[0] = 'A' + (UBYTE) drive;
}
scrp_write (scrapdir); /* Scrap-Directory setzen */
}
make_normalpath(scrapdir,FALSE);
if (!path_exist (scrapdir))
{
if (scrapdir[0]=='A' || scrapdir[0]=='B' ||
scrapdir[0]=='a' || scrapdir[0]=='b')
scrapdir[0] = EOS; /* Kein Klemmbrett auf Disketten! */
else
{
strcpy (s, scrapdir);
s[strlen(s)-1] = EOS; /* Backslash löschen */
if (Dcreate(s)!=0)
{
note(1, NOSCRAP);
scrapdir[0] = EOS; /* Kein Klemmbrett */
}
}
}
if (scrapdir[0]==EOS)
clip_on_disk = FALSE;
strcpy(fsel.suffix,"*.*");
fsel.name[0] = EOS;
init_textring(&undo_text);
clr_undo();
clip_empty = TRUE;
clip_dirty = FALSE;
clip_type = decl_icon_type(icon_test, icon_edit, icon_exist, icon_drag);
cicon = (CICONBLK *)get_obspec(icons, ICLIP);
iclipbrd = add_icon_to_desk(ICLIP, cicon->monoblk.ib_ptext, -1, -1);
add_icon(clip_type,iclipbrd);
}